<?php

class CasesAction extends Action {
   
	public function index(){

        $cateid = isset($_GET["cateid"]) ? $_GET["cateid"] : 0;
        $data['cateid'] = $cateid;
        $cases = M('cases');

        if($cateid == 0){
            $data['cases'] = $cases->join('RIGHT JOIN cate ON cases.cateid = cate.cateid')->select();
        }else{
            $data['cases'] = $cases->join('RIGHT JOIN cate ON cases.cateid = cate.cateid')->where("cate.cateid = '$cateid'")->select();
        }

        $cate = M('cate');
        $data['cate'] = $cate->select();

        $this->assign($data);
        $this->display('cases');
    }


    public function cases_detail(){
        $id = isset($_GET["id"]) ? $_GET["id"] : 0;
        $cases = M('cases');
        $data = $cases->join('RIGHT JOIN cate ON cases.cateid = cate.cateid')->where("id = '$id'")->select();

        $datap = $cases->field('id')->where("id < '$id'")->order('id desc')->limit(1)->find();
//        print_r($datap);
        $datan = $cases->field('id')->where("id > '$id'")->order('id asc')->limit(1)->find();
//        print_r($datan);
        $this->assign('cases', $data);
        $this->assign('previd', $datap);
        $this->assign('nextid', $datan);
        $this->display('cases_detail');
    }

   
}